package com.zhao.dota.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhao.dota.model.LeagueMatch;
import com.zhao.dota.struct.LeagueMatchUsers;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface LeagueMatchMapper extends BaseMapper<LeagueMatch> {

    @Select("SELECT " +
            " lm.*, " +
            " GROUP_CONCAT( lmu.user_id ) as userIds, " +
            " GROUP_CONCAT( lmu.hero_id ) as heroIds, " +
            " GROUP_CONCAT( lmu.hero_name ) as heroNames, " +
            " GROUP_CONCAT( lmu.user_name ) as userNames  " +
            "  FROM " +
            " league_match lm " +
            "  LEFT JOIN league_match_user lmu ON lm.id = lmu.league_match_id  " +
            " WHERE lm.league_id = #{leagueId} " +
            " GROUP BY lm.id")
    Page<LeagueMatchUsers> linkedPage(Page<LeagueMatch> page, Integer leagueId);

}
